numbers = {"zero" : 0, "one" : 1, "two" : 2, "three" : 3, "four" : 4, "five" : 5, "six" : 6, "seven" : 7, "eight" : 8, "nine" : 9}
words = numbers.keys()
line = input().split()
if(len(line) != 3):
    print("Wrong input")
    quit()
for i in range(len(line)):
    if line[i] not in words:
        print("Wrong input")
        quit()
number = numbers[line[0]] * 100 + numbers[line[1]] * 10 + numbers[line[2]]
line = 0
for i in range(2, number // 2):
    if number % i == 0:
        line += 1
if line == 0:
    print(number)
    quit()
else:
    k = 5000
    h = [i for i in range(k + 1)]
    h[1] = 0
    i = 2
    while i <= k ** 0.5:
        if h[i] != 0:
            j = i**2
            while j <= k:
                h[j] = 0
                j = j + i
        i += 1
    h = [i for i in h if h[i] != 0]
    for i in range(len(h)):
        if h[i] < number and h[i + 1] > number:
            if number - h[i] <= h[i + 1] - number:
                print(h[i])
                quit()
            else:
                print(h[i + 1])
                quit()